package com.pearadmin.modules.sys.controller.manage;

import com.github.pagehelper.PageInfo;
import com.pearadmin.common.tools.string.Convert;
import com.pearadmin.common.web.base.BaseController;
import com.pearadmin.common.web.domain.request.PageDomain;
import com.pearadmin.common.web.domain.response.Result;
import com.pearadmin.common.web.domain.response.module.ResultTable;
import com.pearadmin.modules.sys.domain.InvAnodeInputInfo;
import com.pearadmin.modules.sys.service.IInvAnodeInputInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * 导杆投入信息Controller
 *
 * @author Mr.Ling
 * @date 2021-12-18
 */
@RestController
@RequestMapping("/manage/anodeInputInfo")
public class InvAnodeInputInfoController extends BaseController {

    private String prefix = "manage/anodeInputInfo";

    @Autowired
    private IInvAnodeInputInfoService invAnodeInputInfoService;

    @GetMapping("/main")
    @PreAuthorize("hasPermission('/manage/anodeInputInfo/main','manage:anodeInputInfo:main')")
    public ModelAndView main() {
        return jumpPage(prefix + "/main");
    }

    /**
     * 查询导杆投入信息列表
     */
    @ResponseBody
    @GetMapping("/data")
    @PreAuthorize("hasPermission('/manage/anodeInputInfo/data','manage:anodeInputInfo:data')")
    public ResultTable list(@ModelAttribute InvAnodeInputInfo invAnodeInputInfo, PageDomain pageDomain) {
        PageInfo<InvAnodeInputInfo> pageInfo = invAnodeInputInfoService.selectInvAnodeInputInfoPage(invAnodeInputInfo, pageDomain);
        return pageTable(pageInfo.getList(), pageInfo.getTotal());
    }

    /**
     * 新增导杆投入信息
     */
    @GetMapping("/add")
    @PreAuthorize("hasPermission('/manage/anodeInputInfo/add','manage:anodeInputInfo:add')")
    public ModelAndView add() {
        return jumpPage(prefix + "/add");
    }

    /**
     * 新增保存导杆投入信息
     */
    @ResponseBody
    @PostMapping("/save")
    @PreAuthorize("hasPermission('/manage/anodeInputInfo/add','manage:anodeInputInfo:add')")
    public Result save(@RequestBody InvAnodeInputInfo invAnodeInputInfo) {
        return decide(invAnodeInputInfoService.insertInvAnodeInputInfo(invAnodeInputInfo));
    }

    /**
     * 修改导杆投入信息
     */
    @GetMapping("/edit")
    @PreAuthorize("hasPermission('/manage/anodeInputInfo/edit','manage:anodeInputInfo:edit')")
    public ModelAndView edit(Long id, ModelMap mmap) {
        InvAnodeInputInfo invAnodeInputInfo = invAnodeInputInfoService.selectInvAnodeInputInfoById(id);
        mmap.put("invAnodeInputInfo", invAnodeInputInfo);
        return jumpPage(prefix + "/edit");
    }

    /**
     * 修改保存导杆投入信息
     */
    @ResponseBody
    @PutMapping("/update")
    @PreAuthorize("hasPermission('/manage/anodeInputInfo/edit','manage:anodeInputInfo:edit')")
    public Result update(@RequestBody InvAnodeInputInfo invAnodeInputInfo) {
        return decide(invAnodeInputInfoService.updateInvAnodeInputInfo(invAnodeInputInfo));
    }

    /**
     * 删除导杆投入信息
     */
    @ResponseBody
    @DeleteMapping("/batchRemove")
    @PreAuthorize("hasPermission('/manage/anodeInputInfo/remove','manage:anodeInputInfo:remove')")
    public Result batchRemove(String ids) {
        return decide(invAnodeInputInfoService.deleteInvAnodeInputInfoByIds(Convert.toStrArray(ids)));
    }

    /**
     * 删除
     */
    @ResponseBody
    @DeleteMapping("/remove/{id}")
    @PreAuthorize("hasPermission('/manage/anodeInputInfo/remove','manage:anodeInputInfo:remove')")
    public Result remove(@PathVariable("id") Long id) {
        return decide(invAnodeInputInfoService.deleteInvAnodeInputInfoById(id));
    }
}
